package cn.doitedu.day02

import scala.collection.mutable.ArrayBuffer

/**
 * flatMap，扁平化映射操作，即先map在flatten
 */
object FlatMapDemo {


  def main(args: Array[String]): Unit = {

    val arr: Array[Array[Int]] = Array(Array(1,2,3), Array(4,5,6), Array(7,8,9))

    val res1 = arr.flatMap(a => a)
    println(res1.toBuffer)

    //期望将数组中的多个单词，进行拆解，最终返回的是数组中装的一个一个的单词
    val lines: Array[String] = Array("spark hadoop flink", "spark hive", "hadoop spark spark", "flink spark hive flink flink hive")
    //Array("spark", "hadoop", "flink", "spark", "hive", ...)

    val res2 = lines.flatMap(_.split(" "))

    println(res2.toBuffer)


  }

}
